﻿// --------------------------------------------------------------------------------------------------------------------
// <copyright company="DHGMS Solutions" file="PipeDelimited.cs">
//   2004-2012 DHGMS Solutions. Some Rights Reserved. Licensed under GNU General Public License version 2 (GPLv2)
// </copyright>
// --------------------------------------------------------------------------------------------------------------------

namespace Dhgms.TplHelper.Controller.Task.SqlBulkCopy
{
    using Dhgms.DataManager.Model.Info;
    using Dhgms.TplHelper.Model.Info;

    using Kent.Boogaart.KBCsv;

    /// <summary>
    /// Bulk Inserts a pipe-delimited file into MS SQL Server
    /// </summary>
    /// <typeparam name="TInformationClass">
    /// Information Class that represents the file to be loaded
    /// </typeparam>
    public class PipeDelimited<TInformationClass> : Csv<TInformationClass>
        where TInformationClass : Base<TInformationClass>, new()
    {
        #region Constructors and Destructors

        /// <summary>
        /// Initializes a new instance of the <see cref="PipeDelimited{TInformationClass}"/> class. 
        /// </summary>
        /// <param name="taskName">
        /// Name of the data being bulk imported
        /// </param>
        /// <param name="sourceFileName">
        /// Location of the CSV file to import
        /// </param>
        /// <param name="destinationConnectionString">
        /// Connection String for the target database
        /// </param>
        /// <param name="destinationDatabase">
        /// Name of the database the table sits in
        /// </param>
        /// <param name="destinationSchema">
        /// the schema the destination table sits in
        /// </param>
        /// <param name="destinationTable">
        /// the table the data is going to end up in
        /// </param>
        /// <param name="targetTableDeleteAction">
        /// the delete action to be taken on the target table
        /// </param>
        public PipeDelimited(
            string taskName, 
            string sourceFileName, 
            string destinationConnectionString,
            string destinationDatabase,
            string destinationSchema, 
            string destinationTable, 
            DestinationTableDeleteAction targetTableDeleteAction)
            : base(
                taskName, 
                sourceFileName, 
                destinationConnectionString,
                destinationDatabase,
                destinationSchema, 
                destinationTable, 
                targetTableDeleteAction)
        {
        }

        #endregion

        #region Methods

        /// <summary>
        /// Used to change the output format, if needed
        /// </summary>
        /// <param name="output">
        /// output object
        /// </param>
        protected override void OnOverrideFileFormat(CsvReader output)
        {
            output.ValueSeparator = '|';
            output.ValueDelimiter = '"';
        }

        #endregion
    }
}